package com.kmproject.haifu.mvp.presenter;

import android.app.Application;

import com.jess.arms.integration.AppManager;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.http.imageloader.ImageLoader;

import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;

import javax.inject.Inject;

import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.app.utils.RxUtils;
import com.kmproject.haifu.mvp.contract.MyCollectionContract;
import com.kmproject.haifu.mvp.model.api.Api;
import com.kmproject.haifu.mvp.model.entity.ResultBean;
import com.kmproject.haifu.mvp.model.entity.beans.StatisticsBean;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 07/11/2019 17:31
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class MyCollectionPresenter extends BasePresenter<MyCollectionContract.Model, MyCollectionContract.View> {
    @Inject
    RxErrorHandler mErrorHandler;
    @Inject
    Application mApplication;
    @Inject
    ImageLoader mImageLoader;
    @Inject
    AppManager mAppManager;

    @Inject
    public MyCollectionPresenter(MyCollectionContract.Model model, MyCollectionContract.View rootView) {
        super(model, rootView);
    }

    /**
     * 获取统计数据  publish:我求租和租房发布，collection：我的收藏
     * @param type
     */
    public void   myCommonPublishCount(String type)
    {
        mModel.myCommonPublishCount(Api.APP_DOMAIN+"/app/myCommonPublishCount/"+type).compose(RxUtils.applySchedulers(mRootView))
                .subscribe(new ErrorHandleSubscriber<ResultBean<StatisticsBean>>(mErrorHandler) {
                    @Override
                    public void onNext(ResultBean<StatisticsBean> statisticsBeanResultBean) {
                     if (AppUtil.isSuccess(statisticsBeanResultBean))
                     {
                         mRootView.myCommonPublishCountSuccess(statisticsBeanResultBean.getData());
                     }else {
                         mRootView.showMessage(statisticsBeanResultBean.getMessage());
                     }
                    }
                });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mErrorHandler = null;
        this.mAppManager = null;
        this.mImageLoader = null;
        this.mApplication = null;
    }
}
